/*
 * main.js
 * create by Charles Koh
 */

var pgm, main, myOffice, ajax;

(function () {
	var Main = function(args) {
		this.taps = null;
		this.pages = null;
		this.defaultPage = 3;
	};
	Main.prototype = {
		handleEvent: function (event) {
			switch (event.type) {
				case "click":
					pgm.switchTabMenu(event.target.index);
					break;
			}

			return false;
		},
		pageSetup: function(main_tab, page_class) {
			page_class = page_class || "page";
			main_tab = main_tab || "main_tab";
			this.pages = document.getElementsByClassName(page_class);
			for (var i=0, len = this.pages.length; i<len; i++)
				this.pages[i].className += " displayNone";
			this.bindClickTab(main_tab);
		},
		bindClickTab: function(tabId) {
			this.taps = document.getElementById(tabId).children;
			
			for (var i=0, len = this.taps.length; i<len; i++) {
				this.taps[i].index = i;
				addEvent(this.taps[i], "click", this, false);
			}
		}

	};
	
	if (typeof exports !== 'undefined') exports.Main = Main;
	else window.Main = Main;
})();
(function () {
		
	if (!document.getElementsByClassName) {
		document.getElementsByClassName = function (str_class) {
			var nodeList = [];
			var bodyElement = document.getElementsByTagName("body");
			
			
			var childs = bodyElement.children;
		}
	}
	window.onload = function () {
		
		main = new Main();
		main.pageSetup();
		pgm = new PageManager(main.pages);
		pgm.switchTabMenu(main.defaultPage);
		myOffice = new MyOfficePage();
		myOffice.createPage();
		ajax = new Ajax();

		addEvent(document.getElementById('login_state'), 'click', function() {
			pgm.switchTabMenu(6, "/xp/server/login.php");
		}, false);
		
		return true;
	}
	window.onclose = function () {
		return true;
	}
})();
